package demo1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: atp
 * Date: 2022-10-31
 * Time: 16:03
 */
class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if(this.age - o.age > 0) {
            return 1;
        } else if (this.age - o.age < 0){
            return -1;
        } else {
            return 0;
        }
//        return 0;
    }
}
public class Test {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("bit",10);
        students[1] = new Student("gkd",18);
        students[2] = new Student("nb",55);

        Arrays.sort(students);

        System.out.println(Arrays.toString(students));
    }

    public static void main1(String[] args) {
        int[] array = {1,4,2,7,3,8,5};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
